/*
 * client_context.h
 *
 *	Ex: 5
 *
 *  Created on: Jun 6, 2012
 *      Author: Ariel Ayash
 */

#ifndef CLIENT_CONTEXT_H_
#define CLIENT_CONTEXT_H_


#include "common_defs.h"

#include <sys/types.h>
#include <map>
#include <vector>

#define MAXIMAL_CLIENT_NAME_LENGTH (30 + 1)

class ClientContext
{

public:

	explicit ClientContext();
	~ClientContext();

	// add the given client to the list of clients that follows this one.
	void add_to_followers_list( uint follower_sock, ClientContext* follower_context );

	// remove the given client from the list of clients that follows this one.
	void remove_from_followers_list( uint follower_sock );

	// return true if someone follows this client
	bool is_someone_follows();

	// return the list of all clients that follows this one
	void get_followers_list( std::vector<ClientContext*> &list );

	/*
	 * get list of clients that follow this client - this will be used when this client twits
	 * a message.
	 */
	void get_client_followers_socket( std::vector<uint> &list );


	// add the given client to the list of clients that this client follows
	void add_to_followed_list( uint follow_sock, ClientContext* follow_context );

	// remove the given client from the list of clients that this client follows
	void remove_from_followed_list( uint followed_sock );

	// return the list of all clients that this clients follows
	void get_followed_list( std::vector<ClientContext*> &list );

	// return true in case this client doens't follow anybody
	bool is_followed_empty();

	// clear the list of clients that this client follows
	void clear_followed_list();

	void set_client_name( const char *name );

	const char* get_client_name() const;


private:


	std::map< uint, ClientContext* > _followers_clients;	/*< list of clients that follow this
																client. 					>*/

	std::map< uint, ClientContext* > _followed_clients;		/*< list of clients that this client
																follows. 					>*/

	char _name[MAXIMAL_CLIENT_NAME_LENGTH];

};


#endif /* CLIENT_CONTEXT_H_ */
